package com.tianji.learning.mapper;

import com.tianji.learning.domain.po.PointsRecord;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.tianji.learning.enums.PointsRecordType;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 * 学习积分记录，每个月底清零 Mapper 接口
 * </p>
 *
 * @author yp
 * @since 2024-07-30
 */
public interface PointsRecordMapper extends BaseMapper<PointsRecord> {


    @Select("select sum(points) from tj_learning.points_record where user_id = #{userId} and type = #{type} and create_time >= #{begin} and create_time <= #{end}")
    int queryUserTodayPoint(@Param("userId") Long userId,
                            @Param("type") PointsRecordType type,
                            @Param("begin") LocalDateTime begin,
                            @Param("end") LocalDateTime end);

    @Select("select type ,SUM(points) as points  from tj_learning.points_record where user_id = #{userId} and create_time >= #{begin} and create_time <= #{end} group by type")
    List<PointsRecord> queryMyPointToday(@Param("userId") Long userId, @Param("begin") LocalDateTime begin, @Param("end") LocalDateTime end);
}
